﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using System.IO;


namespace HDJ.Framework.Core
{
  public static  class InputSetDataManager
    {

        private const string FileName = "InputSetDataConfig";
        public static Dictionary<string, InputSetData> LoadDataFromFile()
        {
            Dictionary<string, InputSetData> allInputSetDataDic = new Dictionary<string, InputSetData>();
            string path = PathUtils.GetSpecialPath(FileName + ".txt", SpecialPathType.Persistent);
            if (File.Exists(path))
            {
                string text = FileUtils.LoadTextFileByPath(path);
                allInputSetDataDic = JsonUtils.FromJson< Dictionary<string,InputSetData>>(text);
            }
            else
            {
                string textAsset = ResourceManager.LoadText(FileName);
                if (!string.IsNullOrEmpty(textAsset))
                {
                    allInputSetDataDic = JsonUtils.FromJson< Dictionary<string, InputSetData>>(textAsset);


                    FileUtils.CreateTextFile(path, textAsset);
                }
                else
                {
                    Debug.LogError("原始输入设置文件不存在！！");
                }
            }

            return allInputSetDataDic;
        }


        public static Dictionary<string, InputSetData> LoadDataFromFileOnEditor()
        {
            Dictionary<string, InputSetData> allInputSetDataDic = new Dictionary<string, InputSetData>();
            string textAsset = ResourceManager.LoadText(FileName);
            if (!string.IsNullOrEmpty(textAsset))
            {
                allInputSetDataDic = JsonUtils.FromJson<Dictionary<string,InputSetData>>(textAsset);
            }
            else
            {
                Debug.LogError("原始输入设置文件不存在！！");
            }
            return allInputSetDataDic;
        }
        private const string FilePathDic = "Configs/Others/";
        public static void SaveDataOnEditor(Dictionary<string, InputSetData> allInputSetDataDic)
        {
            string path = PathUtils.GetSpecialPath(FilePathDic+FileName + ".txt", SpecialPathType.Resources);

            string text = JsonUtils.ToJson(allInputSetDataDic);
            FileUtils.CreateTextFile(path, text);
        }
    }
}
